﻿using AutoRegistDependency.Attributes;
using HandyWpf.ViewModels;
using HandyWpf.Views;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Wpf.Ui.Controls;

namespace HandyWpf
{
    [Component]
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : HandyControl.Controls.Window
    {
        private readonly MainWindowViewModel mainWindowViewModel;
        private readonly IServiceProvider serviceProvider;
        public MainWindow(MainWindowViewModel mainWindowViewModel, IServiceProvider serviceProvider)
        {
            this.mainWindowViewModel = mainWindowViewModel;
            this.serviceProvider = serviceProvider;
            this.DataContext = mainWindowViewModel;
            InitializeComponent();
            InitRootNavigation();
            //Frame.Content = new Page1();
        }
        private void InitRootNavigation()
        {
            RootNavigation.SetServiceProvider(serviceProvider);
            var menus = mainWindowViewModel.GetMainWinodowMenu();
            RootNavigation.MenuItems.Clear();
            foreach (var menu in menus)
            {
                var item = new NavigationViewItem()
                {
                    Content = menu.Name,
                    Icon = new SymbolIcon() { Symbol = SymbolRegular.Home24 },
                    TargetPageType = GetPageType(menu.ClassName)
                };
                RootNavigation.MenuItems.Add(item);
            }
        }

        private Type? GetPageType(string pageFullName)
        {
            return Type.GetType(pageFullName);
        }
    }
}